﻿using 为web添加unity.caching在controller中注入.DomainModels;
using 为web添加unity.caching在controller中注入.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using EntityFrameworks.Data.Core;
namespace 为web添加unity.caching在controller中注入.Repository
{
    public class OrderRepository : RepositoryBase, IOrderRepository
    {

        public OrderRepository(EEE114Entities db)
            : base(db)
        {

        }
        public IQueryable<Order_List> GetModel()
        {
            var model = from data1 in DB.Order_Info
                        join data2 in DB.Order_Detail
                        on data1.OrderID equals data2.OrderID into list
                        select new Order_List
                        {
                            OrderID = data1.OrderID,
                            ProductCount = list.Count(),
                            UserID = data1.UserID.Value,
                        };
            return model;
        }

        public IEnumerable<Order_List> Fetch(Action<Orderable<Order_List>> order, System.Linq.Expressions.Expression<Func<Order_List, bool>> predicate, int skip, int count)
        {
            var linq = new Orderable<Order_List>(GetModel());
            order(linq);
            return linq.Queryable.Skip(skip)
                                 .Take(count);
        }
    }
}